<?php
// 设置默认地址
require_once $this->website['path']['action'] . '/app/token.php';
$json = array('status' => 'error', 'msg' => '', 'data' => '');

$id = fn_post('id');
$defid = fn_post('defid');

// $basic['uid']
if (!$id || !is_numeric($id)) {
	$json['msg'] = '错误编号';
} elseif (!$this->website['class']['db']
		->table('user_address')
		->where('id=? and uid=?', $id, $basic['uid'])
		->limit(1)
		->count()) {
	$json['msg'] = '未找到地址,或地址已被删除!';
} else {
	$this->website['class']['db']
		->table('user_address')
		->field('def')
		->value(1)
		->where('id=? and uid=?', $id, $basic['uid'])
		->limit(1)
		->update();
	$this->website['class']['db']
		->table('user_address')
		->field('def')
		->value(0)
		->where('id=? and uid=?', $defid, $basic['uid'])
		->limit(1)
		->update();
	$json['status'] = 'ok';
}

$this->json_encode_encrypt($json);
